<?php


namespace App\Admin\Controllers;

use App\Admin\Forms\Setting;
use App\Admin\Lazy\UserAssetsLazy;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Models\SettingModel;
use Dcat\Admin\Grid;
use Dcat\Admin\Form;
use Dcat\Admin\Show;
use App\Admin\Repositories\SettingRepository;

class SettingController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SettingRepository(), function (Grid $grid) {
//            $grid->disableCreateButton();
            $id = $grid->getKeyName();

            $grid->setKeyName($id);
            $grid->newColumn('slug','key名称,必须是英文');
            $grid->column('value','值');
            $grid->column('comment','中文描述');

            $grid->tools('<a class="btn btn-primary disable-inline" href="/admin/setting/add">测试按钮</a>');

        });
    }


    public function add(Content $content)
    {
        return $content
            ->title('app设置')
            ->body(new Card(new Setting()));
    }


    /**
     * Make a show builder.
     *
     * @param mixed $slug
     *
     * @return Show
     */
    protected function detail($slug)
    {
        return Show::make($slug, new SettingRepository(), function (Show $show) {
            $show->setKeyName('slug');

            $show->field('slug');
            $show->field('value');
            $show->field('comment');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SettingRepository(), function (Form $form) {

            $id = $form->getKey();


            $form->keyValue('slug');
            $form->text('value');
            $form->text('comment');


            $form->display('created_at')->label("创建时间");
            $form->display('updated_at')->label("更新时间");
        });
    }



}
